package com.iweb.oasys.service;

import com.iweb.oasys.dao.MenuDao;
import com.iweb.oasys.dao.MeunDaoImpl;
import com.iweb.oasys.entity.Menu;
import com.iweb.oasys.util.ResponseBody;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MenuServiceImpl implements MenuService{
    private MenuDao menuDao = MeunDaoImpl.getInstance();
    private static MenuService menuService = new MenuServiceImpl();
    private MenuServiceImpl() {}
    public static MenuService getInstance() {
        return menuService;
    }

    @Override
    public ResponseBody queryMenuList() throws SQLException {
        ResponseBody responseBody = new ResponseBody();
        List<Menu> menuList = menuDao.queryMenuList();
        int version = menuDao.queryVersion();
        Map<String,Object> map = new HashMap<>();
        map.put("menuData",menuList);
        map.put("menuVersion",version);
        responseBody.setResCode(0);
        responseBody.setData(map);
        return responseBody;
    }

    @Override
    public ResponseBody queryVersion() throws SQLException {
        ResponseBody responseBody = new ResponseBody();
        responseBody.setResCode(0);
        int version = menuDao.queryVersion();
        responseBody.setData(version);
        return responseBody;
    }
}
